package com.moli.iov.open.service.impl;

import com.moli.iov.model.dto.req.PageExtend;
import com.moli.iov.open.model.vo.req.UserVo;
import com.moli.iov.open.service.IUserFacadeService;
import com.moli.iov.rest.RestResponse;
import com.moli.iov.sys.model.dto.req.UserThirdDto;
import com.moli.iov.sys.model.dto.res.UserRoleDto;
import com.moli.iov.sys.model.po.User;
import com.moli.iov.sys.remote.IUserThirdRemoteService;
import com.moli.iov.util.CommonUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户业务
 * </p>
 *
 * @author zql
 * @since 2019/9/21 15:25
 */
@Slf4j
@Service
public class UserFacadeServiceImpl implements IUserFacadeService {

  @Reference(group = "${service.group}", check = false)
  private IUserThirdRemoteService userThirdRemoteService;

  /**
   * 添加用户
   * @param userVo
   * @return
   */
  @Override
  public RestResponse saveUser(UserVo userVo) {
    return userThirdRemoteService.saveUser(convert(userVo));
  }

  /**
   * 分页查询用户列表
   * @param userVo
   * @return
   */
  @Override
  public RestResponse<PageExtend<User>> listUserOfPage(UserVo userVo) {
    return userThirdRemoteService.listUserOfPage(convert(userVo));
  }

  /**
   * 修改用户
   * @param userVo
   * @return
   */
  @Override
  public RestResponse updateUser(UserVo userVo) {
    return userThirdRemoteService.updateUser(convert(userVo));
  }

  /**
   * 重置密码
   * @param userVo
   * @return
   */
  @Override
  public RestResponse resetPwd(UserVo userVo) {
    return userThirdRemoteService.resetPwd(convert(userVo));
  }

  /**
   * 修改密码
   * @param userVo
   * @return
   */
  @Override
  public RestResponse updatePwd(UserVo userVo) {
    return userThirdRemoteService.updatePwd(convert(userVo));
  }

  /**
   * 查询用户角色列表
   * @param userVo
   * @return
   */
  @Override
  public RestResponse<UserRoleDto> getUserRoleByAccount(UserVo userVo) {
    return userThirdRemoteService.getUserRoleByAccount(convert(userVo));
  }

  private UserThirdDto convert(UserVo userVo){
    UserThirdDto userThirdDto = new UserThirdDto();
    CommonUtils.copyProperties(userVo, userThirdDto);
    return userThirdDto;
  }
}
